package com.example.demo.mapper;

import com.example.demo.entity.CourseComment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CourseCommentMapper {
    // 新增课程评论
    @Insert("INSERT INTO course_comments (student_id, course_id, content) VALUES (#{student_id}, #{course_id}, #{content})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertCourseComment(CourseComment courseComment);

    // 删除课程评论
    @Delete("DELETE FROM course_comments WHERE id = #{id}")
    int deleteCourseCommentById(int id);

    // 修改课程评论
    @Update("UPDATE course_comments SET student_id = #{student_id}, course_id = #{course_id}, content = #{content} WHERE id = #{id}")
    int updateCourseComment(CourseComment courseComment);

    // 查询课程评论
    @Select("SELECT * FROM course_comments WHERE id = #{id}")
    CourseComment selectCourseCommentById(int id);

    // 查询所有课程评论
    @Select("SELECT * FROM course_comments")
    List<CourseComment> selectAllCourseComments();

    // 联合查询课程的所有评论
    @Select("SELECT cc.* FROM course_comments cc JOIN courses c ON cc.course_id = c.id WHERE c.id = #{courseId}")
    List<CourseComment> selectCourseCommentsByCourseId(int courseId);
}